<?php
namespace app\vueapi\controller;

use app\common\model\{
    Loss as LossModel, Laboratory as LaboratoryModel, Student as StudentModel,
};

use think\Db;

class Finance extends Base
{
    public function index()
    {
        $data = $this->request->param();
        $page = $data['pageSize'] ?? 10;
        $Laboratory = LaboratoryModel::field('id , name')->paginate($page);
        // $current_page = $Laboratory['data'];
        $res = $Laboratory;
        foreach($Laboratory as $key => $value){
            $loss = LossModel::where('laboratory_id',$value['id'])->field('service , consumables') -> find();
            $student = StudentModel::where('laboratory_id',$value['id'])->field('number , money') -> find();
            // //教室维修费
            $res[$key]['service'] = $loss['service']?$loss['service']:0;
            //教室损耗费
            $res[$key]['consumables'] = $loss['consumables']?$loss['consumables']:0;
            //教室学生数量
            $res[$key]['number'] = $student['number']?$student['number']:0;
            //教室学生学费
            $res[$key]['money'] = $student['money']?$student['money']:0;
            //教室收益
            $res[$key]['income'] = $student['money']*$student['number'];
            //教室学生支出
            $res[$key]['loss'] = $loss['consumables']+$loss['service'];
            //教室产出比
            $res[$key]['sum'] = $student['money']*$student['number'] - $loss['consumables'] - $loss['service'];
        };
        return json(msg(1, $res));
    }
}

?>